﻿// Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'

Shader "UnityShadersBook/Chapter06/Chapter06-HalfLambert"
{
    Properties
    {
        _Diffuse( "Diffuse", Color ) = ( 1.0,1.0,1.0,1.0 )
    }
    SubShader
    {
        Tags { "LightMode" = "ForwardBase" }
        

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            
            #include "Lighting.cginc"

            struct a2v
            {
                float4 vertex : POSITION;
                float3 normal :NORMAL;
            };

            struct v2f
            {
                float4 pos:SV_POSITION;
                //fixed3 color:COLOR;
                float3 worldNormal:TEXCOORD0;
            };
            
            fixed4 _Diffuse;

            v2f vert (a2v v)
            {
                v2f o;
                o.pos = UnityObjectToClipPos( v.vertex );
                o.worldNormal = UnityObjectToWorldNormal( v.normal );
               
               
               
                //o.color = diffuse;
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {

                fixed3 worldLight = normalize( _WorldSpaceLightPos0.xyz );
                fixed3 diffuse = _LightColor0.rgb * _Diffuse.rgb * saturate( dot( i.worldNormal, worldLight )*0.5+0.5 );

                fixed3 color = diffuse + UNITY_LIGHTMODEL_AMBIENT.xyz;
                return fixed4( color, 1.0);
            }
            ENDCG
        }
    }

    Fallback "Diffuse"
}
